package com.yantong.controller.statistics;

import com.yantong.service.IndexService;
import com.yantong.controller.BaseController;
import com.yantong.result.ResultVo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;

/**
 * 首页控制类
 * @author kanghaixin
 * @date 2018/10/11.20:46
 */

@Controller
@RequestMapping("/indexData")
public class IndexController extends BaseController {
    @Autowired
    private IndexService indexService;

    /**
     * 基础数据
     * @return
     */
    @RequiresPermissions("index:base:base")
    @ResponseBody
    @PostMapping("/baseInfo")
    public ResultVo baseInfo() {
        return ResultVo.ok().put("baseInfo", indexService.getIndexBaseInfo(getUserCentreId()));
    }

    /**
     * 数据中心基础数据
     * @return
     */
    @RequiresPermissions("index:base:base")
    @ResponseBody
    @GetMapping("/getDataCenter")
    public ResultVo getDataCenter() {
        return ResultVo.ok().put("dataCenter", indexService.getDataCenter(getUserCentreId()));
    }

    /**
     * 数据中心订单统计图
     * @return
     */
    @RequiresPermissions("index:base:base")
    @ResponseBody
    @GetMapping("/getMonthOrderSumList")
    public ResultVo getMonthOrderSumList(String payTime) {
        return ResultVo.ok().put("monthOrderSumList", indexService.getMonthOrderSumList(getUserCentreId(),payTime));
    }

    /**
     * 数据中心销售报告统计图
     * @return
     */
    @RequiresPermissions("index:base:base")
    @ResponseBody
    @GetMapping("/getYearOrderSumList")
    public ResultVo getYearOrderSumList(String payTimeStart, String payTimeEnd) {
        return ResultVo.ok().put("yearOrderSumList", indexService.getYearOrderSumList(getUserCentreId(),payTimeStart,payTimeEnd));
    }

    /**
     * 数据中心订单商品圆环统计图
     * @return
     */
    @RequiresPermissions("index:base:base")
    @ResponseBody
    @GetMapping("/getTopOrderProduct")
    public ResultVo getTopOrderProduct(String payTime) {
        return ResultVo.ok().put("topOrderProduct", indexService.getTopOrderProduct(getUserCentreId(),payTime));
    }



    /**
     * 新增会员趋势
     * @return
     */
    @RequiresPermissions("index:memberTrend:memberTrend")
    @ResponseBody
    @PostMapping("/memberTrend")
    public ResultVo memberTrend() {
        return ResultVo.ok().put("trend", indexService.getMemberTrend(getUserCentreId()));
    }

    /**
     * 获取会员累积趋势
     * @return
     */
    @ResponseBody
    @PostMapping("/cumulateMemberTrend")
    @RequiresPermissions("index:memberTrend:cumulateMemberTrend")
    public ResultVo cumulateMemberTrend() {
        return ResultVo.ok().put("trend", indexService.getCumulateMemberTrend(getUserCentreId()));
    }

    /**
     * 指定日期用户行为走势
     * @param targetDate
     * @return
     */
    @ResponseBody
    @PostMapping("/memberActionTrend")
    @RequiresPermissions("index:memberTrend:memberActionTrend")
    public ResultVo memberActionTrend(Date targetDate) {
        if (targetDate == null) {
            targetDate = new Date();
        }
        return ResultVo.ok().put("trend", indexService.getMemberActionTrend(getUserCentreId(), targetDate));
    }

    /**
     * 订单趋势
     * @return
     */
    @ResponseBody
    @PostMapping("/orderTrend")
    @RequiresPermissions("index:orderTrend:orderTrend")
    public ResultVo orderTrend() {
        return ResultVo.ok().put("trend", indexService.getOrderTrend(getUserCentreId()));
    }


}
